<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="format-detection" content="telephone=no" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<script src="../../script/mui.min.js"></script>
		<script src="../../script/jquery.min.js"></script>
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/swiper-3.4.2.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/personal.css">
		<link rel="stylesheet" href="../../css/exam.css">
		<title>实习测评分析考试页</title>
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		<style>
			.weui_mask {
				position: fixed;
				z-index: 998;
				top: 0;
				right: 0;
				bottom: 0;
				left: 0;
			}
			.weui_dialog {
				z-index: 999;
			}
			.swiper-wrapper {
				min-height: 400px
			}
			.stu-test .mui-btn-primary {
				color: #fff;
				background-color: #FF9900;
				border: 1px solid #FF9900;
				padding-left: 2em;
				padding-right: 2em;
			}
			.questionItemImgDiv {
				width: 20rem
			}
			.stu-test .mui-btn-primary.mui-active:enabled, .stu-test .mui-btn-primary:enabled:active {
				background-color: #FF9900;
				color: #fff;
				border: 1px solid #FF9900;
			}
		</style>
	</head>
	<body >
		<div class="stu-test" id="scroll">
			<div class="base_style_color" id='BarAppearance' style="height: 22px;width: 100%; position:fixed; left: 0px;top:0px;z-index: 998" ></div>
			<div class="base_navigation_bar base_style_color base_navigation_item_bar" style="position: fixed;left: 0px;top: 20px;">
				<div class="base_navigation_bar base_style_color base_navigation_item_bar">
					<a class="base_left_item" href="#" onclick="backKey()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
					<span id="title">测评分析</span>
				</div>
			</div>
			<div class="space10 " style="margin-top: 64px"></div>
			<!--<div class="k-con-border qusetion-type " >
			<div class="k-con-part" style="position: static">
			<p class="k-text-center k-c323 k-f12">
			<span class="test-score-detail "> 试卷分数：<span class="k-cred" id="score"></span>分 </span>
			<span class="test-score-detail"> 通过分数：<span class="k-cred" id="passscore"></span>分 </span>
			<span class="test-score-detail"> 考试时间：<span class="k-cred" id="kstime"></span>分 </span>
			</p>
			</div>
			</div>-->
			<div class="k-con test-m-bottom70 test-analysis" id="question_div">
				<div class="swiper-container">
					<div class="swiper-wrapper" >
						<!--	<div class="swiper-slide" id="item' + (i + 1) + '" itemtype="' + data[i].qtype + '">
						<div class="k-con-part3 clearfix">
						<span id="itemType" class="k-f18">单选题</span>
						<p class="k-f16 k-c323 k-mt5 indent-5">
						1.不懂就要问
						</p>
						<div class="test-answer-list left_10"  itemtype="' + data[i].qtype + '">
						<div class="mui-input-row mui-radio mui-left " >
						<label>对</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						<div class="mui-input-row mui-radio mui-left " >
						<label>不对</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						<div class="mui-input-row mui-radio mui-left " >
						<label>不懂</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						</div>
						</div>
						</div>
						<div class="swiper-slide" id="item' + (i + 1) + '" itemtype="' + data[i].qtype + '">
						<div class="k-con-part3 clearfix">
						<span id="itemType" class="k-f18">单选题</span>
						<p class="k-f16 k-c323 k-mt5 indent-5">
						2.不懂就要问
						</p>
						<div class="test-answer-list left_10"  itemtype="' + data[i].qtype + '">
						<div class="mui-input-row mui-radio mui-left " >
						<label>对</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						<div class="mui-input-row mui-radio mui-left " >
						<label>不对</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						<div class="mui-input-row mui-radio mui-left " >
						<label>不懂</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						</div>
						</div>
						</div>
						<div class="swiper-slide" id="item' + (i + 1) + '" itemtype="' + data[i].qtype + '">
						<div class="k-con-part3 clearfix">
						<span id="itemType" class="k-f18">单选题</span>
						<p class="k-f16 k-c323 k-mt5 indent-5">
						3.不懂就要问
						</p>
						<div class="test-answer-list left_10"  itemtype="' + data[i].qtype + '">
						<div class="mui-input-row mui-radio mui-left " >
						<label>对</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						<div class="mui-input-row mui-radio mui-left " >
						<label>不对</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						<div class="mui-input-row mui-radio mui-left " >
						<label>不懂</label>
						<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">
						</div>
						</div>
						</div>
						<!--</div>-->
					</div>
				</div>
			</div>
			<div class="k-con1 k-text-center k-fixed-bottom test-bottom1" id="sub_div">
				<div class="k-con-part1">
					<button type="button" class="mui-btn mui-btn-primary"  id="btn1" style="display: none">
						下一题
					</button>
					<button type="button" class="mui-btn mui-btn-primary"  id="btn2" style="display: none">
						提交
					</button>
				</div>
			</div>
			<div class="weui_dialog_alert" id="closeAlert" style="display: none;">
				<div class="weui_mask"></div>
				<div class="weui_dialog">
					<div class="weui_dialog_hd">
						<strong class="weui_dialog_title" id="checkNum2"></strong>
					</div>
					<div class="weui_dialog_ft">
						<a onclick="Cancel()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
					</div>
				</div>
			</div>
			<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
				<div class="weui_mask"></div>
				<div class="weui_dialog">
					<div class="weui_dialog_hd">
						<strong class="weui_dialog_title" id="checkNum">是否确定退出评测</strong>
					</div>
					<div class="weui_dialog_bd"></div>
					<div class="weui_dialog_ft">
						<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
						<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/swiper-3.4.2.jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript">
		var daan = new Object();
		//题目名称数组
		var itemNameArr = new Array();
		//题目id数组
		var itemIdArr = new Array();
		var clickNum = "";
		var pid = "";
		// 计划id
		var cid = "";
		//课程id
		var chapterid = "";
		//章节id
		var tid = "";
		var stime = "";
		var signature = "";
		var mid = "";
		var check_id = "";
		var timeNum = "";
		var questionLen = "";
		var enumber = "";
		var qidArr = new Array();
		var qdaanArr = new Array();
		var answArr = new Array();
		var type = "";
		var message;
		apiready = function() {
			type = api.pageParam.type;
			sendBuriedNotifi('0', '实习评测考试页', '159');
			if (type == 1) {
				$("#title").html('性格测评');
			} else if (type == 2) {
				$("#title").html('行为类型测评');
			} else if (type == 3) {
				$("#title").html('心理成熟度测评');
			}
			$('#btn1').show();
			$('#btn2').hide();
			showProgress();
			loadData();
			getMid();
		}
		//提交数据
		function addReviewData(i, mySwiper) {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				type : type,
				enumber : enumber,
				qid : qidArr[i],
				answer : answArr[i],
				rightansw : qdaanArr[i],
				mid : mid,
			};
			if (answArr[i] == '' || answArr[i] == 'null' || answArr[i] == undefined) {
				ShowToast('请答题');
				return false;
			}
			//			var url_addReview = 'http://base.cfnet.org.cn/index.php/train/review/addReview';
			cfnetppPOST(url_addReview, param, true, function(data, status) {
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						mySwiper.slideNext();
					} else {
						api.toast({
							msg : '提交失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '提交失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		//提交最后一题
		function addEndReviewData(i) {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				type : type,
				enumber : enumber,
				qid : qidArr[i],
				answer : answArr[i],
				rightansw : qdaanArr[i],
				mid : mid,
				message : message
			};
			if (answArr[i] == '' || answArr[i] == 'null' || answArr[i] == undefined) {
				ShowToast('请答题');
				return false;
			}
			cfnetppPOST(url_endReview, param, true, function(data, status) {
				if (type == 1) {
					param['message'] = '《性格测评》';
					SendBusinessOperationsLogNotifi('实习评测考试页', '159', param, param, '', data, '提交性格测评接口', '159-01');
				} else if (type == 2) {
					param['message'] = '《行为类型测评》';
					SendBusinessOperationsLogNotifi('实习评测考试页', '159', param, param, '', data, '提交行为类型测评接口', '159-02')
				} else if (type == 3) {
					param['message'] = '《心理成熟度测评》';
					SendBusinessOperationsLogNotifi('实习评测考试页', '159', param, param, '', data, '提交心理成熟度测评接口', '159-02')
				}
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						var list = data.data;
						sendNotifi();
						openEvaluationAnalysisScore(list.tit, list.cont);
					} else {
						api.toast({
							msg : '提交失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '提交失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		function sendNotifi() {
			api.sendEvent({
				name : 'RefreshPracticeNotifi'
			});
		}

		function scoreAlertYes() {
			api.closeWin({
			});
		}

		function loadData() {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				type : type,
			};
			//			var url_getReview = 'http://base.cfnet.org.cn/index.php/train/review/getReview';
			cfnetppPOST(url_getReview, param, true, function(data, status) {
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						var list = data.data;
						if (list != null && list != "") {
							enumber = list.enumber;
							if (list.shitiarr != null && list.shitiarr != '') {
								GetReviewData(list.shitiarr, list.sum);
							} else {
								PopupHint2('题目为空');
							}
						} else {
							PopupHint2('暂无试题');
						}
					} else {
						api.toast({
							msg : '获取测验题目数据失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '获取测验题目数据失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		function getMid() {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				//				jid : $api.getStorage('cfnetppjxid'),
				type : type,
				enumber : enumber,
			};
			//			var url_startReview = 'http://base.cfnet.org.cn/index.php//train/review/startReview';
			cfnetppPOST(url_startReview, param, true, function(data, status) {
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						var list = data.data;
						if (list != null && list != "") {
							mid = list;
						}
					} else {
						api.toast({
							msg : '获取数据失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '获取数据失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		function GetReviewData(shitiarr, len) {
			var questionArr = new Array();
			for (var i = 0; i < len; i++) {
				var question = shitiarr[i.toString()];
				questionArr.push(question);
			}
			SetUI(questionArr);
		}

		// 滚动监听
		function listenScroll() {
			var maxHeight = $(".ReviewWeekly_div").height() + 10;
			var testResultHeight = $(".test-result").height() + 10;
			$(window).resize(function() {
				var thisHeight = $(this).height();
				if (winHeight - thisHeight > 50) {
					//当软键盘弹出，在这里面操作
					$("#sub_div").css('display', 'none');
				} else {
					$("#sub_div").css('display', 'block');
					//当软键盘收起，在此处操作
				}
			});
		}

		function PopupHint2(str) {
			$("#checkNum2").text(str);
			$('#closeAlert').show();
		}

		function Cancel() {
			$('#closeAlert').hide();
			backClick();
		}

		//得到答案数据
		function GetAnswerData(slideNumber) {
			var duooptionid = '';
			//多选题选项id
			var danoptionid = '';
			//单选题选项id
			var duoQuestionid = '';
			//多选题题目id
			var danQuestionid = '';
			var duoObject = new Object();
			//单选题tiid
			var lunshuQuestionid = "";
			//论述题id
			var duoQuestionidArr = new Array();
			var lunshuContent = '';
			var itemtype = $(".swiper-wrapper").children().eq(slideNumber).attr('itemtype');
			qidArr[slideNumber] = $(".swiper-wrapper").children().eq(slideNumber).attr('qid');
			qdaanArr[slideNumber] = $(".swiper-wrapper").children().eq(slideNumber).attr('qdaan');
			//获取题目类型
			if (itemtype == '1' || itemtype == '2' || itemtype == '3' || itemtype == '5' || itemtype == '7' || itemtype == '8' || itemtype == '9') {//单选题,多选题,判断题
				$(".swiper-wrapper").children().eq(slideNumber).find('input').each(function(i) {
					if ($(this).attr('type') === 'radio') {
						if (this.checked == true) {
							danoptionid = $(this).attr('dataindex');
							danQuestionid = $(this).attr('itemid');
							answArr[slideNumber] = $(this).attr('dataindex');
						}
					} else if ($(this).attr('type') === 'checkbox') {
						if (this.checked == true) {
							duooptionid = $(this).attr('dataindex');
							Itemindex = $(this).attr('dataindex');
							duoQuestionid = $(this).attr('itemid');
						} else {
							duooptionid = $(this).attr('dataindex');
							Itemindex = $(this).attr('dataindex');
							duoQuestionid = $(this).attr('itemid');
							duoObject[duooptionid] = "";
							delete duoObject[duooptionid];
						}
						if (JSON.stringify(duoObject) == "{}") {
						}
						daan[duoQuestionid] = duoObject;
					}
				});
			} else {
				$(".swiper-wrapper").children().eq(slideNumber).find('textarea').on('input', function() {
					lunshuQuestionid = $(this).attr('itemid');
					//				//论述题内容
					lunshuContent = $(this).val();
					Itemindex = $(this).attr('Itemindex');
					if (lunshuContent != null && lunshuContent != '') {
						$("#scroll-card").find("span").eq(Itemindex).removeClass('qusetion-num-normal').addClass('qusetion-num-selected');
					}
					daan[lunshuQuestionid] = lunshuContent;
				});
			}
			//			popu(answArr);
		}

		//选择题
		function panxuanzeReturnStr(i) {
			var num = (i + 1) % 2;
			switch(num) {
				case 0:
					return '错'
					break;
				case 1:
					return '对'
					break;
				default:
					return '暂无'
					break;
			}
		}

		function SetUI(list) {
			var qxuan = '';
			var data = list;
			questionLen = data.length;
			var OrderNumStr = ''
			var questionStr = "";
			var xuanzeStr = "";
			var questionsItemImgstr = "";
			var xuanzheImgstr = "";
			for (var i = 0; i < questionLen; i++) {
				itemIdArr.push(data[i].qid);
				qxuan = qxuanxiangIsNull(data[i].qxuanxiang);
				OrderNumStr = (i + 1) + '/' + questionLen;
				$(".swiper-wrapper").append('<div class="swiper-slide" id="item' + (i + 1) + '"  onclick="GetAnswerData(' + i + ')"   itemtype="' + data[i].qtype + '" qid="' + data[i].qid + '"  qdaan="' + data[i].qdaan + '"   ></div>')
				if (data[i].qtype == 1 || data[i].qtype == 3 || data[i].qtype == 8) {
					if (data[i].questions.toString().indexOf("img") > 0) {
						questionsItemImgstr = PicDomainName(getpicurl(data[i].questions.match(/<img.*?src=\"(.+?)\"/)[1]), 320);
						questionStr = htmlspecialchars_decode(data[i].questions) + '<img class="questionItemImgDiv" src="' + questionsItemImgstr + '" alt="">';
					} else {
						questionsItemImgstr = "";
						questionStr = htmlspecialchars_decode(data[i].questions);
					}
					$("#item" + (i + 1)).append('<div class="k-con-part3 clearfix">' + '<span id="itemType" class="k-f18">' + ByIdGetQuestionTypeName(data[i].qtype) + '</span>' + '<p class="k-f16 k-c323 k-mt5 indent-5">' + OrderNumStr + "." + "(" + data[i].qfenshu + "分 " + ")" + questionStr + '</p>' + '<div class="test-answer-list left_10"  itemtype="' + data[i].qtype + '"   >' + '</div>' + '</div>')
					//	是单选或判断
					for (var k = 0; k < qxuan.length; k++) {
						if (data[i].qtype != 3) {
							if (qxuan[k].xuanzhe.toString().indexOf("img") > 0) {
								xuanzheImgstr = PicDomainName(getpicurl(qxuan[k].xuanzhe.match(/<img.*?src=\"(.+?)\"/)[1]), 120);
								xuanzeStr = htmlspecialchars_decode(qxuan[k].xuanzhe) + '<img class="xuanzeImgDiv" src="' + xuanzheImgstr + '" alt="">';
							} else {
								xuanzheImgstr = "";
								xuanzeStr = htmlspecialchars_decode(qxuan[k].xuanzhe);
							}
						} else {
							xuanzeStr = panxuanzeReturnStr(k)
						}
						$("#item" + (i + 1) + " .test-answer-list").append('<div class="mui-input-row mui-radio mui-left " >' + '<label>' + xuanzeStr + '</label>' + '<input Itemindex="' + i + '" dataindex="' + (k + 1) + '" name="radio' + data[i].qid + '" type="radio"   itemid="' + data[i].qid + '">' + '</div> ')
					}
				}
				$(".mui-slider-item  img").width("90%");
				$(".mui-input-row  img").height("50%");
			}
			var mySwiper = new Swiper('.swiper-container', {
				autoHeight : true,
				//用户操作swiper之后，是否禁止autoplay
				autoplayDisableOnInteraction : true,
				direction : 'horizontal',
				allowSwipeToPrev : false,
				loop : false,
				onlyExternal : true,
				onSlideChangeStart : function(swiper) {
					if (mySwiper.activeIndex != mySwiper.slides.length - 1) {
						$('#btn1').show();
						$('#btn2').hide();
					} else {
						$('#btn1').hide();
						$('#btn2').show();
					}
				},
			})
			// 底部按钮
			$('#btn1').click(function() {
				addReviewData(mySwiper.activeIndex, mySwiper);
			});
			$('#btn2').click(function() {
				addEndReviewData(mySwiper.activeIndex);
			});
		}

		function kebackListen() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				//coding...
				backKey()
			});
		}

		function backKey() {
			$('#offlineAlert').show();
		}

		function cleanCancel() {
			$('#offlineAlert').hide();
		}

		//确定
		function cleanConfirm() {
			$('#offlineAlert').hide();
			backClick();
		}

		function backClick() {
			sendBuriedNotifi('1', '实习评测考试页', '159');
			api.closeWin({
			});
		}
		
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}

		//打开测验结果页
		function openEvaluationAnalysisScore(tit, cont) {
		    sendBuriedNotifi('1', '实习评测考试页', '159');
			var y = 0;
			var h = api.winHeight - y;
			api.openWin({useWKWebView:true,
				name : 'Practice_EvaluationAnalysisScore',
				url : 'Practice_EvaluationAnalysisScore.html',
				rect : {
					x : 0,
					y : y,
					w : 'auto',
					h : h,
				},
				pageParam : {
					title : tit,
					content : cont,
					type : type
				},
				bounces : false,
				vScrollBarEnabled : true,
				hScrollBarEnabled : false
			});
			setTimeout(function() {
				api.closeWin();
			}, 1000);
		}
	</script>
</html>